package filter

const (
	nullFp     = 0
	bucketSize = 4
)

type bucket [bucketSize]byte

// insert 桶中插入指纹
func (this *bucket) insert(fp byte) bool {
	for i, slot := range this {
		if slot == nullFp {
			this[i] = fp
			return true
		}
	}
	return false
}

// delete 桶中删除指纹
func (this *bucket) delete(fp byte) bool {
	for i, slot := range this {
		if slot == fp {
			this[i] = nullFp
			return true
		}
	}
	return false
}

// getFingerprintIndex 获取指纹在桶中的索引
func (this *bucket) getFingerprintIndex(fp byte) int {
	for i, slot := range this {
		if slot == fp {
			return i
		}
	}
	return -1
}

// reset 重置桶
func (this *bucket) reset() {
	for i := range this {
		this[i] = nullFp
	}
}
